var rm1 = {
    buttons: [],
    msg: function(s) {
	if(window.console) { console.log(s); }
	document.getElementById('status').innerHTML = s;
    },
    clear: function() {
	rm1.buttons = [];
    },
    change_state: function(obj, state) {
	e = document.getElementById(obj);
	e.innerHTML = "" + obj + ": " + state;
    },
    check_buttons: function() {
	if(rm1.buttons[0] == '1') {      
	    rm1.msg('open gate');
	    setTimeout(function() { rm1.change_state('gate', 'closed'); }, 5000);
	    rm1.change_state('gate', 'open');
	    rm1.clear();
	}
	if(rm1.buttons[0] == '2') {
	    rm1.msg('open door');
	    setTimeout(function() { rm1.change_state('door', 'closed'); }, 5000);
	    rm1.change_state('door', 'open');
	    rm1.clear();
	}
	if(rm1.buttons[0] == '*') {
	    rm1.msg('clear');
	    rm1.clear();
	}
    },
    c: function(button) {
	if(button == '*') {
	    rm1.msg("");
	    rm1.clear();
	    return;
	}
	rm1.buttons.push(button);
	rm1.msg(rm1.buttons);
	rm1.check_buttons();
    }
};